package com.example.keshe.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.keshe.entity.CarData;
import com.example.keshe.mapper.CarDataMapper;
import com.example.keshe.mq.MIdObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;
import java.util.stream.Collectors;

@RestController
public class drawController {

    @Autowired
    MIdObject mIdObject;

    @Autowired
    CarDataMapper carDataMapper;

    @RequestMapping("/huabu")
    public String getHuaBu(){
        System.out.println(mIdObject.getList());
        return mIdObject.getStr();
    }



    @RequestMapping("/picture11")
    public double[][] getPicture11(){
        double[][] arr=new double[1000][2];



        List<CarData> carDataList = carDataMapper.selectList(new QueryWrapper<>());
        List<Integer> list1=new ArrayList<>();
        List<Integer> list2=new ArrayList<>();

        for(CarData carData:carDataList){
            list1.add(carData.getDecentering());
            list2.add(carData.getAorc());
        }



        Integer max1 = Collections.max(list1);
        System.out.println(max1);

        for(int i=0;i<list1.size();i++){
            double temp=(double)list1.get(i)/(double)max1;
            arr[i][0]=temp;
        }


        Integer max2 = Collections.max(list1);
        max2-=1500;

        for(int i=0;i<list2.size();i++){

            double temp=(double) (list2.get(i)-1500)/(double)max2;
            temp=Math.abs(temp);
            arr[i][1]=temp;
        }

        double[][] res = Arrays.copyOf(arr, list1.size());
        System.out.println(res.length);
        return res;
    }




    @RequestMapping("/picture22")
    public double[][] getPicture22(){
        double[][] arr=new double[1000][2];



        List<CarData> carDataList = carDataMapper.selectList(new QueryWrapper<>());
        List<Integer> list1=new ArrayList<>();
        List<Integer> list2=new ArrayList<>();

        for(CarData carData:carDataList){
            list1.add(carData.getDecentering());
            list2.add(carData.getLPwm()-carData.getRPwm());
        }



        Integer max1 = Collections.max(list1);
        System.out.println(max1);

        for(int i=0;i<list1.size();i++){
            double temp=(double)list1.get(i)/(double)max1;
            arr[i][0]=temp;
        }


        Integer max2 = Collections.max(list1);


        for(int i=0;i<list2.size();i++){

            double temp=(double) list2.get(i)/(double)max2;
            temp=Math.abs(temp);
            arr[i][1]=temp;
        }

        double[][] res = Arrays.copyOf(arr, list1.size());
        return res;
    }
}

